package com.wanmait.cookBook.servlet.admin;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanmait.cookBook.dao.ReportDao;
import com.wanmait.cookBook.vo.Pager;
import com.wanmait.cookBook.vo.Report;

/**
 * Servlet implementation class ReportServlet
 */
@WebServlet("/ReportServlet")
public class ReportServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReportServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		request.setCharacterEncoding("utf-8");
		
		String action=request.getParameter("action");
		
		
		if("prohibitUser".equals(action))
		{
			this.prohibitUser(request, response);
		}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	/*
	 * protected void report(HttpServletRequest request, HttpServletResponse
	 * response) throws ServletException, IOException { // TODO Auto-generated
	 * method stub ArrayList<Report> arry=ReportDao.getReportDao().checkReport();
	 * 
	 * request.setAttribute("arry",arry);
	 * 
	 * request.getRequestDispatcher("/back/report.jsp").forward(request, response);
	 * }
	 */
	
	protected void prohibitUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int userid=Integer.parseInt(request.getParameter("id"));
		
		boolean c= ReportDao.getReportDao().prohibitUser(userid);
		
		int one=1;
		int zero=0;
		if (c==true) {
			ReportDao.getReportDao().userStatus(userid,zero);
		}
		if (c==false) {
			ReportDao.getReportDao().userStatus(userid,one);
		}
	}
	
		
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}


}





